package com.sand.controller;

import com.sand.dto.Owner.ExecutionDelete;
import com.sand.dto.Owner.MerchantOrOwner;
import com.sand.entity.buy.execution;
import com.sand.result.ResponseResult;
import com.sand.service.ExecutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/execution")
public class ExecutionController {

    @Autowired
    private ExecutionService executionService;

    /**
     *添加方案预执行
     */
    @PostMapping("/add")
    public ResponseResult<Integer> add(@RequestBody execution execution){

        Integer i =  executionService.add(execution);
        return new ResponseResult<Integer>().ok(i);
    }


    /**
     *查询与该商家.客户相关的方案预执行
     */
    @PostMapping("/selectById")
    public ResponseResult<List<execution>> selectById(@RequestBody MerchantOrOwner merchantOrOwner){
        List<execution> list = executionService.selectById(merchantOrOwner);
        return new ResponseResult<List<execution>>().okResult(list,"查询成功");
    }


    /**
     * 修改方案预执行
     */
    @PostMapping("/upd")
    private ResponseResult<Integer> upd(@RequestBody execution execution){
        Integer i = executionService.upd(execution);
        return new ResponseResult<Integer>().ok(i);
    }

    /**
     *删除方案预执行
     */
    @PostMapping("/down")
    private ResponseResult<Integer> down(@RequestBody ExecutionDelete executionDelete){
        Integer i = executionService.down(executionDelete);
        return new ResponseResult<Integer>().ok(i);
    }

}
